package com.da.lon.wang.xlg.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;

import com.da.lon.wang.xlg.MyApplication;
import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.WaitGoods;
import com.da.lon.wang.xlg.bean.WaitGoods.WaitGoodsDetail;
import com.da.lon.wang.xlg.util.ViewHolder;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

public class OutGoodsSubAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<WaitGoodsDetail> goods;
    private WaitGoods goods2;
    private Activity context;
    private ImageLoader loader;

    public OutGoodsSubAdapter(List<WaitGoodsDetail> list, WaitGoods good,
                              Activity context) {

        inflater = LayoutInflater.from(context);
        loader = ImageLoader.getInstance();
        this.context = context;

        if (list == null) {
            good = new WaitGoods();
        } else {
            this.goods = list;
            this.goods2 = good;
        }

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return goods != null ? goods.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return goods.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        try {
            WaitGoodsDetail good = goods.get(position);

            convertView = inflater.inflate(
                    R.layout.ouka_seller_out_listviewitem_sub, null);

            TextView m_order_id = ViewHolder.get(convertView, R.id.m_order_id);
            TextView nameTextView = ViewHolder.get(convertView, R.id.wait_name);
            TextView quantityTextView = ViewHolder.get(convertView,
                    R.id.wait_quantity);
            TextView weightTextView = ViewHolder.get(convertView,
                    R.id.wait_weight);
            TextView priceTextView = ViewHolder.get(convertView,
                    R.id.wait_price);
            ImageView waitImageView = ViewHolder.get(convertView,
                    R.id.wait_image);

            m_order_id.setText("单号：" + goods2.getMerger_sn());
            nameTextView.setText(good.getProducts_name());
            quantityTextView.setText("×" + good.getProducts_quantity());
            priceTextView.setText("￥" + goods2.getOrders_total());
            weightTextView.setText(good.getWeight());

            waitImageView.setScaleType(ScaleType.CENTER_CROP);
            MyApplication.loadImageByPicasso(context, good.getBigimage(), null, waitImageView, 0, 0, 1);

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return convertView;
    }

}
